package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ReceiptManagement;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.ReceiptManagementQueryObj;
import cn.wolfcode.crm.service.IReceiptManagementService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("receiptManagement")
public class ReceiptManagementController {

    @Autowired
    IReceiptManagementService receiptManagementService;

    @RequestMapping("")
    @RequiresPermissions(value = {"收款管理首页","receiptManagement:index"} ,logical = Logical.OR)
    public String index(){

        return "receiptManagement/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"收款管理列表","receiptManagement:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(ReceiptManagementQueryObj qo){
        PageResult result = receiptManagementService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return receiptManagementService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"收款管理保存","receiptManagement:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(ReceiptManagement entity){
        JSONResult result = new JSONResult();
        try{
            receiptManagementService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"收款管理更新","receiptManagement:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(ReceiptManagement entity){
        JSONResult result = new JSONResult();
        try{
            receiptManagementService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("已审核,不允许修改");
        }
        return result;
    }

    @RequestMapping("audit")
    @RequiresPermissions(value = {"收款管理审核","receiptManagement:audit"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult audit(Long id){
        JSONResult result = new JSONResult();
        try{
            receiptManagementService.audit(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("已审核 不允许操作");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"收款管理删除","receiptManagement:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            receiptManagementService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
